package com.yy.mapper;

import com.github.pagehelper.Page;
import com.yy.anno.AutoFill;
import com.yy.dto.SetmealDTO;
import com.yy.dto.SetmealPageQueryDTO;
import com.yy.entity.Setmeal;
import com.yy.enumeration.OperationType;
import com.yy.vo.DishItemVO;
import com.yy.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {


    Page<SetmealVO> list(SetmealPageQueryDTO dto);

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);


    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    Setmeal selectById(Long id);

    void delete(List<Long> ids);

    SetmealVO getById(Long id);

    void enableOrDisable(Integer status, Long id);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> listSetmeal(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
}
